package main

import (
	"fmt"
	"github.com/garyburd/redigo/redis"
)


func main() {
	conn,err := redis.Dial("tcp","192.168.1.201:6379")
	if err != nil {
		fmt.Println("connect redis error :",err)
		return
	}
	defer conn.Close()
	_, err = conn.Do("SET", "alarmand1", "receiveOK")
	if err != nil {
		fmt.Println("redis set error:", err)
	}
	////设置key的过期时间
	//_, err = conn.Do("expire", "name", 10) //10秒过期
	//if err != nil {
	//	fmt.Println("set expire error: ", err)
	//	return
	//}
	//
	name, err := redis.String(conn.Do("GET", "alarmand1"))
	if err != nil {
		fmt.Println("redis get error:", err)
	} else {
		fmt.Printf("Got name: %s \n", name)
	}
    //删除key
	//_, err = conn.Do("DEL", "askmeatadmin")
	//if err != nil {
	//	fmt.Println("err while deleting:", err)
	//}

	////判断key是否存在
	//is_key_exit, err := redis.Bool(conn.Do("EXISTS", "name"))
	//if err != nil {
	//	fmt.Println("err while checking keys:", err)
	//} else {
	//	fmt.Println(is_key_exit)
	//}


	//批量获取mget、批量设置mset
	//_, err = conn.Do("MSET", "name1", "wd","age",22)
	//if err != nil {
	//	fmt.Println("redis mset error:", err)
	//}
	//res, err := redis.Strings(conn.Do("MGET", "name1","age"))
	//if err != nil {
	//	fmt.Println("redis get error:", err)
	//} else {
	//	res_type := reflect.TypeOf(res)
	//	fmt.Printf("res type : %s \n", res_type)
	//	fmt.Printf("MGET name: %s \n", res)
	//	fmt.Println(len(res))
	//}
	//结果：
	//res type : []string


}